<#import "/lib/composition.ftl" as ui />
<#import "/lib/spring.ftl" as spring />

<@ui.composition "/base.ftl">
  <#assign content in ui>
    <div id="page-title">
      <div id="page-title-inner">
        <div class="container">
          <h2 style="margin-left: -40px;">Edit model</h2>
        </div>
      </div>
    </div>
  
    <div id="wrapper">
      <div class="container">           
        <hr>
        
        <div class="row">         
          <div class="span3">
            <form method="POST" enctype="multipart/form-data" action="<@spring.url '/admin/asdfgh/saveModel' />">
              <fieldset>
                <@spring.formHiddenInput 'modelForm.docId' />
              
                <label>Title: </label>
                <@spring.formInput 'modelForm.title' />
                
                <div>&nbsp;</div>
                
                <label>Description: </label>
                <@spring.formTextarea 'modelForm.description' />
                
                <div>&nbsp;</div>
                
                <label>Order: </label>
                <@spring.formInput 'modelForm.order' />
                
                <div>&nbsp;</div>
                
                <label>
                  <input type="checkbox" name="visibleInMain" <#if modelForm.visibleInMain>checked="true"</#if> />
                  visible in main                    
                </label>
                                
                <div>&nbsp;</div>
                
                <label>                    
                  <input type="checkbox" name="visibleInPortfolio" <#if modelForm.visibleInPortfolio>checked="true"</#if> />
                  visible in portfolio                   
                </label>                                  
                
                <div>&nbsp;</div>
              
                <button class="btn btn-inverse">Save</button>
              </fieldset>
            </form>
          </div>          
        
          <#if modelForm.docId != ''>
            <div class="span9">
              <div class="row">
                <#list images as image>                                      
                  <div class="span3" style="margin-bottom: 20px;"> 
                    <div class="picture">
                      <form id="deleteForm_${image_index}" action="<@spring.url '/admin/asdfgh/deleteImage/${modelForm.docId}/${image_index}' />" style="text-align: right; margin-bottom: 0px;" method="post">
                        <a href="#" onclick="document.getElementById('deleteForm_${image_index}').submit();"><i class="icon-remove" style="padding-right: 5px;"></i></a>                                                   
                      </form>
                    
                      <a href="<@spring.url '/attachment/${modelForm.docId}?name=${(image.fullImage)!}'/>" rel="image">
                        <img src="<@spring.url '/attachment/${modelForm.docId}?name=${(image.previewImage)!}'/>">
                      </a>                        
                    </div>
                  </div>
                </#list>
              </div>
              
              <div class="row">                
                <form method="POST" enctype="multipart/form-data" action="<@spring.url '/admin/asdfgh/addImage/${modelForm.docId}' />">
                  Add image:&nbsp;
                  <input type="file" name="image" />
                  <button class="btn btn-inverse">Upload</button>            
                </form>
              </div>
            </div>
          </#if>
        </div>
        
        <div style="height:700px;">&nbsp;</div>
      </div>
    </div>
  </#assign>
</@ui.composition>
